﻿
%using System;
%using System.IO;
%using System.Linq;
%using NetFluid;
%using Sito.Model;

%page inherit Index;

%page route "download";

% override Body

%if (session("User") != null && session("User").Status == User.UserStatus.Admin)
     
    %Files.Values.ForEach(x => x.SaveAs(Path.Combine("./Release",x.FileName)));
     
%end if

% var names = Directory.GetFiles("./Release").Select(x => Path.GetFileName(x));
<div class="content" style="background-color:{%rand_color()%};">
    <span style="text-align:right">
        <h2>NetFluid 4.0</h2>
    </span>
    <ul style="text-align:left">
        <li>
            % var win = names.Where(x=>x.StartsWith("NetFluid.win")).OrderByDescending(x=>x);
            %if(win.Count()>0)
                <a href="{%win.First()%}"><h2>NetFluid Windows Installer</h2></a>
                <ul>
                    % foreach(var f in win)
                        <li>
                            <a href="/{%f%}">{%f%}</a>
                        </li>
                    % end foreach
                </ul>
            %end if
        </li>
        <li>
            % var mono = names.Where(x=>x.StartsWith("NetFluid.mono")).OrderByDescending(x=>x);
            %if(mono.Count()>0)
                <a href="{%mono.First()%}"><h2>NetFluid Archive for Mono (require Mono 2.10)</h2></a>
                <ul>
                    % foreach(var f in mono)
                        <li>
                            <a href="/{%f%}">{%f%}</a>
                        </li>
                    % end foreach
                </ul>
            %end if
        </li>
        <li>
            % var source = names.Where(x=>x.StartsWith("NetFluid.utility")).OrderByDescending(x=>x);
            %if(source.Count()>0)
                <a href="{%source.First()%}"><h2>NetFluid.dll Source Code</h2></a>
                <ul>
                    % foreach(var f in source)
                        <li>
                            <a href="/{%f%}">{%f%}</a>
                        </li>
                    % end foreach
                </ul>
            %end if
        </li>
    </ul>

    %var others = names.Except(win.Union(mono).Union(source));

    %if(others.Count()>0)
        <h1>Others and tools</h1>
        <ul>
            %foreach(var o in others)
                <li>
                    <a href="/{%o%}">{%o%}</a>
                </li>
            %end foreach
        </ul>
    %end if

    %if (session("User") != null && session("User").Status == User.UserStatus.Admin)
        <form method="post" enctype="multipart/form-data" action="/download">
            <input type="file" name="file" /><input type="submit" value="Upload" />
        </form>
    %end if
</div>

%end override 